﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace weatherinfo
{
    public class Local
    {
        private XmlNode m_xml;

        private string m_city;
        private string m_state;
        private float m_latitude;
        private float m_longitude;
        private string m_time;
        private int m_timezone;
        private int m_daylight;

        public Local()
        {
            init();
        }
        public Local(XmlNode localnode)
        {
            init();
            m_xml = localnode;
            LoadXml(m_xml);
        }
        public void LoadXml(XmlNode localnode)
        {
            if (localnode.Name != "local")
                return;
            for (int i = 0; i < localnode.ChildNodes.Count; i++)
            {
                XmlNode node = localnode.ChildNodes[i];
                if (node.Name == "city")
                    m_city = node.InnerText;
                else if (node.Name == "state")
                    m_state = node.InnerText;
                else if (node.Name == "lat")
                    m_latitude = Single.Parse(node.InnerText);
                else if (node.Name == "lon")
                    m_longitude = Single.Parse(node.InnerText);
                else if (node.Name == "time")
                    m_time = node.InnerText;
                else if (node.Name == "timeZone")
                    m_timezone = Int32.Parse(node.InnerText);
                else if (node.Name == "obsDaylight")
                    m_daylight = Int32.Parse(node.InnerText);
            }
        }

        private void init()
        {
            m_city = "";
            m_state = "";
            m_latitude = 0;
            m_longitude = 0;
            m_time = "";
            m_timezone = 0;
            m_daylight = 0;
        }
    }
}
